/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SessionBean;

import Entity.TbAdmin;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author CHINHNB
 */
@Stateless
public class SessionBeanTbAdmin implements SessionBeanTbAdminRemote {
    @PersistenceContext(unitName = "EJBModule_ToursAndTravelPU")
    private EntityManager em;

    public void persist(Object object) {
        em.persist(object);
    }

    @Override
    public boolean bmCheckLogin(String name, String password) {
        boolean flag=false;
        List<TbAdmin> listAdmin=bmGetAllAdmin();
        for (TbAdmin tbAdmin : listAdmin) {
            if(tbAdmin.getAUserName().equals(name)&&tbAdmin.getAPassword().equals(password)){
                flag=true;
            }
        }
        return flag;
    }

    @Override
    public List<TbAdmin> bmGetAllAdmin() {
        List<TbAdmin> listAdmin=em.createNamedQuery("TbAdmin.findAll").getResultList();
        return listAdmin;
    }
 
}
